﻿//Copyright (c) Microsoft Corporation. All rights reserved.

using Microsoft.Ted.Wacel;
using System.Collections.Generic;
using System.Diagnostics;

namespace Microsoft.Ted.Wacel.TestConsole.PerformanceTests
{
    public class CachedCubePerfTester
    {
        public static int Rollup(Stopwatch watch)
        {
            Cache.Cube cube = new Cache.Cube("perf_cube");
            cube.Clear();
            cube.Dimensions.Add("Time", Dimension.GetTimeDimensionMonthDayHour5Minutes(2013));
            var months = cube.Dimensions["Time"].Children[0].Children;
            int count = 0;
            watch.Restart();
            foreach (var month in months)
            {
                foreach (var day in month.Children)
                {
                    foreach (var hour in day.Children)
                    {
                        foreach (var min in hour.Children)
                        {
                            cube.Update(
                                new List<DataPoint>{new DataPoint {
                                Coordinates = new List<DimensionNode> {min},
                                Value = 1.0
                            }});
                            count++;
                            if (count >= 10)
                                break;
                        }
                        if (count >= 10)
                            break;

                    }
                    if (count >= 10)
                        break;

                }
                if (count >= 10)
                    break;

            }
            watch.Stop();
            VisualTester.AreEqual(10.0, (double)cube.Query(new { Time = "2013" }).Value);
            return count;
        }
     
    }
}
